﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Data;
using YWTSSys.Library;
using System.Data.Common;
using Microsoft.Practices.EnterpriseLibrary.Data;
using Microsoft.Practices.EnterpriseLibrary.Data.Sql;
using YWTSSys.Model;

namespace YWTSSys.DAL
{
    public  class TelRecordDAL
    {
        public static int Add(TelRecordInfo obj, int 需回访天数)
        {
            Database DB = DatabaseFactory.CreateDatabase();

            DbCommand dbCommand = DB.GetStoredProcCommand("TelRecord_Add", obj.客户ID, obj.UserId, obj.RealName, obj.通话时间, obj.通话内容, obj.通话时长, obj.是否需回访, 需回访天数, obj.回访电话记录ID);
            return Convert.ToInt32(DB.ExecuteScalar(dbCommand));
        }
        public static IDataReader GetByCustomerIDTop20(int 客户ID)
        {
            Database DB = DatabaseFactory.CreateDatabase();

            DbCommand dbCommand = DB.GetStoredProcCommand("TelRecord_GetByCustomerIDTop20", 客户ID);
            return DB.ExecuteReader(dbCommand);
        }
        public static IDataReader GetByID(int ID)
        {
            Database DB = DatabaseFactory.CreateDatabase();

            DbCommand dbCommand = DB.GetStoredProcCommand("TelRecord_GetByID", ID);
            return DB.ExecuteReader(dbCommand);
        }
        public static DataTable GetPagination(string WhereSql, int PageIndex, int PageSize, string Sort, ref int TotalCount)
        {
            Database DB = DatabaseFactory.CreateDatabase();

            DbCommand dbCommand = DB.GetStoredProcCommand("TelRecord_GetPagination");
            DB.AddInParameter(dbCommand, "WhereSql", DbType.String, WhereSql);
            DB.AddInParameter(dbCommand, "PageIndex", DbType.Int32, PageIndex);
            DB.AddInParameter(dbCommand, "PageSize", DbType.Int32, PageSize);
            DB.AddInParameter(dbCommand, "Sort", DbType.String, Sort);
            DB.AddOutParameter(dbCommand, "TotalCount", DbType.Int32, 8);
            DataTable dt = DB.ExecuteDataSet(dbCommand).Tables[0];

            TotalCount = Convert.ToInt32(DB.GetParameterValue(dbCommand, "TotalCount"));
            return dt;
        }
        /// <summary>
        /// 业务员获取其需回访的电话记录
        /// </summary>
        /// <param name="UserId"></param>
        /// <returns></returns>
        public static DataTable GetMyNeedBackTel(int UserId)
        {
            Database DB = DatabaseFactory.CreateDatabase();
            DbCommand dbCommand = DB.GetStoredProcCommand("TelRecord_GetMyNeedBackTel", UserId);
            return DB.ExecuteDataSet(dbCommand).Tables[0];
            
        }
    }
}
